package cn.rkylin.oms.order.service;

import cn.rkylin.core.IDataBaseFactory;
import cn.rkylin.oms.common.base.AbstractAdapterFactory;
import cn.rkylin.oms.item.domain.SkuGroup;
import cn.rkylin.oms.item.vo.SkuVO;
import cn.rkylin.oms.order.domain.EcOrder;
import cn.rkylin.oms.order.domain.EcTrade;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 平台订单服务层实现
 *
 * @author wangxing
 * @version 1.0
 * @created 2017.10.09
 */
@Service("orderService")
public class OrderServiceImpl extends AbstractAdapterFactory implements IOrderService {

	@Autowired
	protected IDataBaseFactory dao;

	public OrderServiceImpl() {

	}

	/**
	 * 获取待进系统的平台订单数据集
	 *
	 * @param reqMap
	 * @return
	 * @throws Exception
	 */
	public List<EcTrade> selectTradeList(Map<String, String> reqMap) throws Exception {
		return dao.findForList("selectEcTradeForSysOrderInsert", reqMap);
	}

	/**
	 * 获取平台订单商品明细数据集
	 *
	 * @param reqMap
	 * @return
	 * @throws Exception
	 */
	public List<EcOrder> selectTradeOrderList(Map<String, Object> reqMap) throws Exception {
		return dao.findForList("selectEcOrderForSysOrder", reqMap);
	}

	/**
	 * 获取平台订单商品明细对应平台商品信息数据集
	 *
	 * @param reqMap
	 * @return
	 * @throws Exception
	 */
	public List<SkuVO> selectItemSkuList(Map<String, Object> reqMap) throws Exception {
		return dao.findForList("selectEcSkuForSysOrder", reqMap);
	}

	/**
	 * 获取平台订单商品明细对应平台商品组合商品信息数据集
	 *
	 * @param reqMap
	 * @return
	 * @throws Exception
	 */
	public List<SkuGroup> selectItemSkuGroupList(Map<String, Object> reqMap) throws Exception {
		return dao.findForList("selectEcSkuGroupForSysOrder", reqMap);
	}

	/**
	 * 更新平台订单状态(进系统标识状态)
	 *
	 * @param record
	 * @return
	 * @throws Exception
	 */
	public int updateByPrimaryKeySelectiveEcTrade(EcTrade record) throws Exception {
		return dao.update("updateByPrimaryKeySelectiveEcTrade", record);
	}

	/**
	 * 获取状态变化的平台订单数据集(用于更新系统订单状态)
	 *
	 * @param reqMap
	 * @return
	 * @throws Exception
	 */
	public List<EcTrade> selectChangeTradeList(Map<String, String> reqMap) throws Exception {
		return dao.findForList("selectEcTradeForSysOrderUpdate", reqMap);
	}

	/**
	 * 查询平台订单信息
	 * 
	 * @author jipengcheng
	 * @param reqMap
	 * @return
	 * @throws Exception
	 */
	public EcTrade selectByEcTradeCodeAndShopIdEcTrade(Map<String, Object> reqMap) throws Exception {
		return (EcTrade) dao.find("selectByEcTradeCodeAndShopIdEcTrade", reqMap);
	}

}